
import streamlit as st
import pandas as pd


def analyze(parser, input_data):

    st.title('合同审查日志分析')

    st.markdown("### 合同输入数据：")
    st.write(input_data)

    st.markdown("### 合同文本分块：")
    contents = parser.get_block_contents(input_data)
    df = pd.DataFrame(contents)
    st.write(df)

    st.markdown("### 合同要素抽取：")
    extracts = parser.get_extracts(input_data)
    df = pd.DataFrame(extracts)
    df.drop(columns=['fileId', 'id'], inplace=True, errors='ignore')
    columns = ['name', 'extractHint', 'recalls', 'prompt', 'related_ids', 'content', 'paragraph_id']
    df = df.reindex(columns=columns)
    st.write(df)

    st.markdown("### 合同语义审查：")
    reviews = parser.get_reviews(input_data)
    df = pd.DataFrame(reviews)
    df.drop(columns=['fileId', 'id'], inplace=True, errors='ignore')
    columns = ['name', 'extractHint', 'checkHint', 'recalls', 'prompt', 'related_ids',
               'content', 'paragraph_id', 'check_label', 'reason']
    df = df.reindex(columns=columns)
    st.write(df)
